﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public class GestureSteps : MonoBehaviour, IGestureHandler {
    [Serializable]
    public struct Step
    {
        public string name;
    }
    public List<Step> steps = new List<Step>();
    public int curStep = -1;
    protected Dictionary<string, GestureBase> detectors = new Dictionary<string, GestureBase>();

    public List<string> detectorNames = new List<string>();
    public List<GestureBase> detectorObjects = new List<GestureBase>();

    void Start()
    {
        InitDetectors();
        BeginStep(0);
    }

    void InitDetectors()
    {
        if (detectorNames.Count != detectorObjects.Count)
        {
            Debug.LogError("Detectors Match Errors");
        }
        for (int i = 0; i < detectorNames.Count; ++i)
        {
            detectorObjects[i].Handler = this;
            detectors[detectorNames[i]] = detectorObjects[i];
        }
    }

    void BeginStep(int stepIdx)
    {
        if(0>=stepIdx && stepIdx<steps.Count)
        {
            curStep = stepIdx;
            string gestureName = steps[stepIdx].name;
            var e = detectors.GetEnumerator();
            while (e.MoveNext())
            {
                if (e.Current.Key == gestureName)
                {
                    e.Current.Value.enabled = true;
                }
                else
                {
                    e.Current.Value.enabled = false;
                }
            }
        }
        else
        {
            RandomStep();
        }
    }

    void RandomStep()
    {

    }

    public void OnDetectStart()
    {
        
    }

    public void OnDetectProgress(float grogress)
    {
        
    }

    public void OnDetectFinish()
    {
        
    }

    public void OnDetecCancel()
    {
        
    }
}
